package Square;

import java.awt.Color;
import java.awt.Toolkit;
import java.net.URL;

import javax.swing.JPanel;

import Monopol.MonopolExceptions.InsufficientFunds;
import Monopol.AssetGroups.AssetGroup;
import Player.Player;


/**
 * @author Avia Tam
 * @author Assaf Miron
 * 
 */
public class Square implements Negotiable {

    private String name; // The Name of the Square

    /**
     * @author Avia Tam
     * @author Assaf Miron
     * Same Value Enum
     */
    public enum sameOwner {

	ALL_ASSETS_SAME_OWNER(1), NOT_SAME_OWNER(0);
	private Integer value;

	private sameOwner(Integer value) {
	    this.value = value;
	}

	public Integer getValue() {
	    return value;
	}
    }

    public enum fixedSquares {

	START_SQUARE(0),
	PRISON_SQUARE(9),
	PARKING_SQUARE(18),
	GO2PRISON_SQUARE(27);
	private Integer squareValue;

	private fixedSquares(Integer value) {
	    this.squareValue = value;
	}

	public Integer get() {
	    return squareValue;
	}

	public void set(Integer value) {
	    this.squareValue = value;
	}
    }

    public Square() {
	super();
	this.name = "Square";
    }

    /**
     * @param string
     */
    public Square(String name) {
	super(); // Object Constructor
	this.name = name; // Initialize the Square Name
    }

    /**
     * @return the Services Cost
     */
    // Name Getter and Setter
    public String getName() {
	return name;
    }

    public void setName(String name) {
	this.name = name;
    }

    /**
     * @return
     */
    public Player getOwner() {
	// Implemented in Children
	return null;
    }

    /**
     * Check if the Asset can be Bought or not
     * @return True if the Asset can be bought, False otherwise
     */
    public boolean isBuyable() {
	return false;
    }

    /**
     * Check if the Asset can be Sold or not
     * @return True if the Asset can be sold, False otherwise
     */
    public boolean isSellable() {
	return false;
    }

    ;

    /**
     * Buy the Asset if it is possible
     * @param Player The Player that wants to buy this Asset
     * @throws InsufficientFunds
     */
    public void buy(Player player) throws InsufficientFunds {
    }

    /**
     * Sell the Asset if it is possible
     * @param Player The Player that wants to Sell This Asset
     */
    public void sell(Player player) {
    }

    @Override
    public String toString() {
	return this.name;
    }

    public boolean isAsset() {
	return false;
    }

    /**
     * gets the stay price , relevant only assets
     */
    public Double getStay_price() {
	return null;
    }

    /**
     * this is only for City
     */
    public void buyHouse() throws InsufficientFunds {
    }

    public Boolean isCity() {
	return false;
    }

    public void deleteOwner() {
	// Implemented in Children
    }


    /* (non-Javadoc)
     * @see Square.Negotiable#getGroup()
     */
    @Override
    public AssetGroup getGroup() {
	// Implemented in Children
	return null;
    }


    /* (non-Javadoc)
     * @see Square.Negotiable#setOwner(Player.Player)
     */
    @Override
    public void setOwner(Player player) {
	// Do Nothing - Implemented in Children
    }


    /* (non-Javadoc)
     * @see Square.Negotiable#getCost()
     */
    @Override
    public Double getCost() {
	// Do Nothing - Implemented in Children
	return null;
    }


    /* (non-Javadoc)
     * @see Square.Negotiable#getColor()
     */
    @Override
    public Color getColor() {
	// Return a Default Color
	return Color.white;
    }


    /* (non-Javadoc)
     * @see Square.Negotiable#draw()
     */
    @Override
    public JPanel draw() {
	// Implemented in Children
	return null;
    }

    /**
     * @return The Image Icon String of the Sqaure based on its name
     */
    public String getIcon() {
	URL imageURL = null;
	try {
	    // Get the Image Icon based on the Square Name
	    imageURL = Toolkit.class.getResource("/images/squares/" + this.name.toLowerCase() + ".gif");

	} catch (Exception e) {
	    // Probably no Image Icon
	    imageURL = null;
	}

	// Check if the image Exists
	if (imageURL != null) {
	    return "/squares/" + this.name.toLowerCase() + ".gif";
	} else {
	    return "";
	}
    }

    public String getDetails() {
	return name;
    }

}
